import QtQuick
import QtQuick.Controls

Rectangle {
    id: statesPanel
    width: 300
    height: 400

    color: "#bb000000"
    border.width: 2
    border.color: "#bb333333"
    radius: 10

    ListModel {
        id: statesModel
    }

    ListView {
        id: listView
        anchors.margins: 10
        anchors.fill: parent
        model: statesModel
        delegate: Item {
            width: listView.width
            height: 20
            Row {
                spacing: 10
                anchors.fill: parent
                Text {
                    id: labelText
                    text: model.label + ": "
                    width: 80
                    elide: Text.ElideRight
                    color: "#efefef"
                }
                Text {
                    id: stateText
                    text: model.stateText
                    width: parent.width - labelText.width - 20
                    elide: Text.ElideRight
                    color: "#efefef"
                }
            }
        }
    }

    function set(label, stateText) {
        // Look for an existing item with the same label
        for (var i = 0; i < statesModel.count; i++) {
            if (statesModel.get(i).label === label) {
                statesModel.setProperty(i, "stateText", stateText);
                return;
            }
        }
        // If not found, add a new item
        statesModel.append({ label: label, stateText: stateText });
    }
}
